﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IISDeploy.Domain.Core
{
    public class Cluster
    {
        #region Fields
        private int id;        
        private List<Server> servers;
        private string name;
        private string virtualAddress;
        private string description;

        #endregion

        #region Properties

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public string VirtualAddress
        {
            get { return virtualAddress; }
            set { virtualAddress = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public List<Server> Servers
        {
            get { return servers; }
            set { servers = value; }
        }

        #endregion

        #region Methods

        public void AddServer(Server item)
        {
            this.servers.Add(item);
        }

        public Server GetServerByName(string name)
        {
            return this.servers.Find(delegate(Server s) { return s.Name.Equals(name); });
        }

        public Server GetServerByIpAddress(string ipAddress)
        {
            return this.servers.Find(delegate(Server s) { return s.IpAddress.Equals(ipAddress); });
        }

        public Server GetServerById(int id)
        {
            return this.servers.Find(delegate(Server s) { return s.Id.Equals(id); });
        }

        public Cluster()
        {
            this.servers = new List<Server>();            
        }

        public bool RemoveServer(Server item)
        {
            return this.servers.Remove(item);
        }

        #endregion
    }
}
